import 'package:flutter/services.dart';
import 'package:zrjz/comm/utils/log_utils.dart';

class AppChannel {
  static const platform = MethodChannel('com.room/opapp');

  /// 检查图片包含人脸的数量
  static Future<int> checkFace(String path) async {
    try {
      final int result = await platform.invokeMethod('checkFace', path);
      return result;
    } on PlatformException catch (e) {
      Log.e(e.message ?? 'checkFace Channel 错误');
      return -1;
    }
  }

  /// 苹果账户登录
  static Future<Map?> appleLogin() async {
    try {
      final Map result = await platform.invokeMethod('appleLogin');
      return result;
    } on PlatformException catch (e) {
      Log.e(e.message ?? 'appleLogin Channel 错误');
      return null;
    }
  }

  /// 拿到原生平台的路由地址
  static Future<String> getNativeRouterName() async {
    try {
      return await platform.invokeMethod('getNativeRouterName');
    } on PlatformException catch (e) {
      Log.e(e.message ?? 'getNativeRouterName Channel 错误');
      return '';
    }
  }

  /// 清除原生平台的路由地址
  static Future<bool> clearNativeRouterName() async {
    try {
      return await platform.invokeMethod('clearNativeRouterName');
    } on PlatformException catch (e) {
      Log.e(e.message ?? 'clearNativeRouterName Channel 错误');
      return false;
    }
  }

  /// 把原生平台的App带到后台
  static Future<void> bringAppToBackground() async {
    try {
      await platform.invokeMethod('bringAppToBackground');
    } on PlatformException catch (e) {
      Log.e(e.message ?? 'bringAppToBackground Channel 错误');
    }
  }

  /// 安卓专用，跳过Splash页面
  static Future<bool> skipAndroidSplashScreen() async {
    try {
      return await platform.invokeMethod('skipAndroidSplashScreen');
    } on PlatformException catch (e) {
      Log.e(e.message ?? 'skipAndroidSplashScreen Channel 错误');
      return false;
    }
  }
}
